package com.tobeface.sns.infrastructure.persist.blog.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Repository;

import com.kissme.core.orm.Page;
import com.tobeface.sns.domain.blog.Blog;
import com.tobeface.sns.infrastructure.persist.CrudMongoRepositorySupport;
import com.tobeface.sns.infrastructure.persist.blog.BlogRepository;
import com.tobeface.sns.interfaces.util.UserUtil;

/**
 * @author Linxiaosheng
 */
@Repository
public class BlogRepositoryImpl extends CrudMongoRepositorySupport<Blog, String> implements BlogRepository {

	@Autowired
	protected BlogRepositoryImpl(MongoOperations mongoOperations) {
		super(mongoOperations);
	}

	public Blog save(Blog blog) {
		return super.save(blog.setCreateTime(String.valueOf(new Date().getTime())));
	}

	public Blog findOne(String id) {
		return super.findOne(id);
	}

	public Page<Blog> findPage(Page<Blog> page) { 
		
		page.getParams().put("memberId", UserUtil.getCurrentLoginUser().getMember().getId()); 
		return super.findPage(page);
		
	}

	public void delete(String id) {
		super.delete(id);
	}

}
